home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Genie / Projects / Pedestal / Source / Sources / Views / PedViewScroll.cc < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-24  |  3.8 KB  |  240 lines

  1. /*    ================
  2.  *    PedViewScroll.cc
  3.  *    ================
  4.  */
  5.  
  6. #include "PedestalDebugging.h"
  7.  
  8. #include <MacWindows.h>
  9.  
  10. #include "PedViewScroll.hh"
  11.  
  12. #include "PedPane.hh"
  13. #include "PedViewScroller.hh"
  14.  
  15. //UPedNullView gNullView;
  16.  
  17. static const Point sPointZero = {0, 0};
  18.  
  19. PedViewScroll::PedViewScroll(PedPaneSubView &inSuperPane)
  20. : PedViewSub(inSuperPane), mPane(NULL), mScrollPos(sPointZero), mScroller(NULL)
  21. {
  22. }
  23.  
  24. PedViewScroll::~PedViewScroll()
  25. {
  26.     if (mPane) mPane->release();
  27.     if (mScroller) mScroller->release();
  28. }
  29.  
  30. void
  31. PedViewScroll::Dispose()
  32. {
  33.     if (mScroller) {
  34.         mScroller->Dispose();
  35.         mScroller->release();
  36.         mScroller = NULL;
  37.     }
  38.     if (mPane) {
  39.         mPane->Dispose();
  40.         mPane->release();
  41.         mPane = NULL;
  42.     }
  43. }
  44.  
  45.  
  46. enum {kPedMsgNone, kPedMsgScroll, kPedMsgNotifyScrolledTo};
  47.  
  48. long
  49. PedViewScroll::Message(long inMsgCode, void *inData)
  50. {
  51.     switch (inMsgCode) {
  52.         case kPedMsgScroll:
  53.             // We need a block here
  54.             if (1) {
  55.                 short dh = (long)inData & 0xFF;
  56.                 short dv = (long)inData >> 16;
  57.                 Scroll(dh, dv);
  58.             }
  59.             break;
  60.         case kPedMsgNone:
  61.             break;
  62.         default:
  63.             break;
  64.     }
  65.     return 0;
  66. }
  67.  
  68.  
  69. void
  70. PedViewScroll::GetScrollPos(Point &outPos)
  71. {
  72.     outPos = mScrollPos;
  73. }
  74.  
  75. void
  76. PedViewScroll::GetFrame(Rect &outFrame)
  77. {
  78.     PedViewSub::GetFrame(outFrame);
  79.     //::OffsetRect(&outFrame, -mScrollPos.h, -mScrollPos.v);
  80. }
  81.  
  82. void
  83. PedViewScroll::DoScroll(short inH, short inV)
  84. {
  85.     Scroll(inH, inV);
  86.     // Notify scroller that scrolling has occurred, to update the scrollbars.
  87.     if (mScroller) {
  88.         mScroller->Message(kPedMsgNotifyScrolledTo, &mScrollPos);
  89.     }
  90. }
  91.  
  92. void
  93. PedViewScroll::Scroll(short inH, short inV, bool inUpdate)
  94. {
  95.     if (mPane) {
  96.         mScrollPos.h += inH;
  97.         mScrollPos.v += inV;
  98.     }
  99.     //Refresh();
  100.     
  101.     Rect frame;
  102.     GetFrame(frame);
  103.     RgnHandle updateRegion;
  104.     updateRegion = ::NewRgn();  // always initialize the update region
  105.     ::ScrollRect(&frame, -inH, -inV, updateRegion);
  106.     if (inUpdate) {
  107.         // Update immediately
  108.         ::SetClip(updateRegion);
  109.         Rect box = (*updateRegion)->rgnBBox;
  110.         ::EraseRect(&box);
  111.         DrawContent();
  112.         ::ClipRect(&qd.thePort->portRect);
  113.     } else {
  114.         ::InvalRgn(updateRegion);
  115.     }
  116.     ::DisposeRgn(updateRegion);
  117. }
  118.  
  119. void
  120. PedViewScroll::GetWindowToLocalOffset(Point &outOffset)
  121. {
  122.     GetWindowToFrameOffset(outOffset);
  123.     
  124.     Point pos;
  125.     GetScrollPos(pos);
  126.     outOffset.h -= pos.h;
  127.     outOffset.v -= pos.v;
  128. }
  129.  
  130. PedPane *
  131. PedViewScroll::Pane()
  132. {
  133.     return mPane;
  134. }
  135.  
  136. void 
  137. PedViewScroll::SetPane(PedPane *inPane)
  138. {
  139.     PedPane *oldPane = mPane;
  140.     if (inPane) inPane->retain();
  141.     mPane = inPane;
  142.     if (oldPane) oldPane->release();
  143. }
  144.  
  145. void
  146. PedViewScroll::SetScroller(PedViewScroller *inScroller)
  147. {
  148.     PedViewScroller *oldScroller = mScroller;
  149.     if (inScroller) inScroller->retain();
  150.     mScroller = inScroller;
  151.     if (oldScroller) oldScroller->release();
  152. }
  153.  
  154.  
  155. void
  156. PedViewScroll::Focus()
  157. {
  158.     PedViewSub::Focus();
  159.     Rect frame;
  160.     GetFrame(frame);
  161.     ::ClipRect(&frame);
  162. }
  163.  
  164. void
  165. PedViewScroll::Open()
  166. {
  167.     if (mPane) {
  168.         mPane->Open();
  169.     }
  170. }
  171.  
  172. void
  173. PedViewScroll::Close()
  174. {
  175.     if (mPane) {
  176.         mPane->Close();
  177.     }
  178. }
  179.  
  180. void
  181. PedViewScroll::Activate()
  182. {
  183.     if (mPane) {
  184.         mPane->Activate();
  185.     }
  186. }
  187.  
  188. void
  189. PedViewScroll::Deactivate()
  190. {
  191.     if (mPane) {
  192.         mPane->Deactivate();
  193.     }
  194. }
  195.  
  196. void
  197. PedViewScroll::DrawContent()
  198. {
  199.     if (mPane) {
  200.         //Rect frame;
  201.         //GetFrame(frame);
  202.         //::ClipRect(&frame);
  203.         //::EraseRect(&frame);
  204.         mPane->DrawContent();
  205.         //::ClipRect(&qd.thePort->portRect);
  206.     }
  207. }
  208.  
  209. void
  210. PedViewScroll::Resize(short inWidth, short inHeight)
  211. {
  212.     PedViewSub::Resize(inWidth, inHeight);
  213.     if (mPane) {
  214.         //mPane->Resize(inWidth, inHeight);
  215.     }
  216. }
  217.  
  218. void
  219. PedViewScroll::DispatchNullEvent(EventRecord &inEvent)
  220. {
  221.     //PedViewSub::DispatchNullEvent(inEvent);
  222.     if (mPane) {
  223.         mPane->DispatchNullEvent(inEvent);
  224.     }
  225. }
  226.  
  227. void
  228. PedViewScroll::DispatchClickEvent(EventRecord &inEvent)
  229. {
  230.     //PedViewSub::DispatchClickEvent(inEvent);
  231.     if (mPane) {
  232.         mPane->DispatchClickEvent(inEvent);
  233.     }
  234. }
  235.  
  236. void
  237. PedViewScroll::DispatchKey(EventRecord &inEvent)
  238. {
  239. }
  240.